package com.example.clxy.service.impl;

import com.example.clxy.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author weichong
 * date 2020-08-06
 * @Description:
 */
@Service
public class SendMailServiceImpl implements SendMailService {

    @Value("${spring.mail.username}")
    private String whoAmI;

    @Autowired
    private JavaMailSender mailSender;

    /**
     *
     * @param to  收件人Email地址
     * @param subject 邮件主题
     * @param content 邮件主题内容
     */
    @Override
    @Async
    public void sendSimpleMail(String to, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        message.setFrom(whoAmI);
        mailSender.send(message);
    }

}
